use std::io;
use std::path::PathBuf;

use actix_files as fs;
use actix_files::NamedFile;
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, web};
use actix_web::Result;
use env_logger::{Env};
use actix_web::middleware::Logger;


async fn index(req: HttpRequest) -> Result<NamedFile> {
    let path: PathBuf = req.match_info().query("filename").parse().unwrap();
    println!("{}", path.display());
    Ok(NamedFile::open(path)?)
}

#[actix_web::main]
async fn main() ->io::Result<()>{
    env_logger::init_from_env(Env::default().default_filter_or("info"));
    HttpServer::new(||App::new()
        // .route("/{filename:.*}",web::get().to(index))
        .wrap(Logger::default())
        .service(fs::Files::new("/static","./static").show_files_listing())
        .service(fs::Files::new("/web","./advanced_static_files_01/web").show_files_listing())
        .service(fs::Files::new("/web2","./web").show_files_listing())
        .route("/demo",web::get().to(||async { "hiiii" }))
    )
        .bind("127.0.0.1:8080")?
        .run()
        .await
}

